package com.maslyk.invitation;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

/**
 *
 * @author Administrator
 */
public class PageTools
{	
    public static boolean isDigit(char chr)
    {
        if (chr >= '0' && chr <= '9')
        {
            return true;
        }
        return false;
    }

    public static void addMessage(Throwable ex)
    {
        FacesContext.getCurrentInstance().addMessage(ex.getMessage(), new FacesMessage(ex.getMessage(), ex.getMessage()));
    }

    public static double round(double value)
    {
        return Math.rint(value * Math.pow(10, 2)) / Math.pow(10, 2);
    }

    public static void addFieldMessages(String fieldId, String message)
    {
        FacesContext context = FacesContext.getCurrentInstance();
        FacesMessage msg = new FacesMessage(message);
        msg.setSeverity(FacesMessage.SEVERITY_WARN);

        context.addMessage(fieldId, msg);
    }

    public static void addErrorMessage(Throwable ex)
    {
        MessageBean message = new MessageBean(ex);
        BeanService.putRequestScopeBean("MessageBean", message);
    }

}
